<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>修改简历</title>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            line-height: 1.6;
            color: #333;
            max-width: 900px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f9f9f9;
        }
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 2px solid #3498db;
        }
        .profile {
            display: flex;
            align-items: center;
            gap: 20px;
        }
        .avatar {
            border-radius: 50%;
            border: 3px solid #3498db;
            object-fit: cover;
        }
        .contact-info {
            background-color: #f0f8ff;
            padding: 15px;
            border-radius: 5px;
            margin-bottom: 20px;
        }
        h1 {
            color: #2c3e50;
            margin: 0;
        }
        h2 {
            color: #3498db;
            border-bottom: 1px solid #ddd;
            padding-bottom: 5px;
            margin-top: 25px;
        }
        .section {
            background-color: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
            margin-bottom: 20px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
            color: #2c3e50;
        }
        input[type="text"],
        input[type="email"],
        input[type="tel"],
        input[type="date"],
        textarea,
        select {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        textarea {
            min-height: 100px;
            resize: vertical;
        }
        button {
            background-color: #3498db;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s;
            margin-right: 10px;
        }
        button:hover {
            background-color: #2980b9;
        }
        .btn-danger {
            background-color: #e74c3c;
        }
        .btn-danger:hover {
            background-color: #c0392b;
        }
        .btn-success {
            background-color: #2ecc71;
        }
        .btn-success:hover {
            background-color: #27ae60;
        }
        .item-container {
            border: 1px solid #eee;
            padding: 15px;
            margin-bottom: 15px;
            border-radius: 4px;
            position: relative;
        }
        .remove-btn {
            position: absolute;
            top: 10px;
            right: 10px;
            background-color: #e74c3c;
            color: white;
            border: none;
            width: 25px;
            height: 25px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
        }
        .add-btn {
            background-color: #2ecc71;
            margin-top: 10px;
        }
        .form-actions {
            text-align: right;
            margin-top: 20px;
        }
        .upload-form {
            margin-top: 10px;
            padding: 10px;
            background-color: #f0f8ff;
            border-radius: 5px;
        }
        input[type="file"] {
            margin: 10px 0;
        }
    </style>
</head>
<body>
<form th:action="@{'/updateResume/' + ${user.id}}" method="post" enctype="multipart/form-data">
    <div class="header">
        <div>
            <h1>修改简历</h1>
        </div>
        <div class="profile">
            <img class="avatar" th:src="@{'/images/' + ${user.avatar_path}}" width="100" height="100" alt="头像"/>
        </div>
    </div>

    <div class="section contact-info">
        <h2>基本信息</h2>
        <div class="form-group">
            <label for="name">姓名</label>
            <input type="text" id="name" name="name" th:value="${user.name}" required>
        </div>
        <div class="form-group">
            <label for="position_applied">应聘岗位</label>
            <input type="text" id="position_applied" name="position_applied" th:value="${user.position_applied}" required>
        </div>
        <div class="form-group">
            <label for="phone">电话</label>
            <input type="tel" id="phone" name="phone" th:value="${user.phone}" required>
        </div>
        <div class="form-group">
            <label for="email">邮箱</label>
            <input type="email" id="email" name="email" th:value="${user.email}" required>
        </div>
        <div class="form-group">
            <label for="address">地址</label>
            <input type="text" id="address" name="address" th:value="${user.address}">
        </div>

        <div class="upload-form">
            <label for="file"><strong>更新头像:</strong></label><br>
            <input type="file" name="file">
        </div>
    </div>

    <div class="section">
        <h2>教育背景</h2>
        <div id="education-container">
            <div class="item-container" th:each="edu, iterStat : ${educations}">
                <button type="button" class="remove-btn" onclick="removeItem(this)">×</button>
                <input type="hidden" th:name="|educations[${iterStat.index}].id|" th:value="${edu.id}">
                <div class="form-group">
                    <label th:for="|educations[${iterStat.index}].school_name|">学校名称</label>
                    <input type="text" th:id="|educations[${iterStat.index}].school_name|"
                           th:name="|educations[${iterStat.index}].school_name|"
                           th:value="${edu.school_name}" required>
                </div>
                <div class="form-group">
                    <label th:for="|educations[${iterStat.index}].major|">专业</label>
                    <input type="text" th:id="|educations[${iterStat.index}].major|"
                           th:name="|educations[${iterStat.index}].major|"
                           th:value="${edu.major}" required>
                </div>
                <div class="form-group">
                    <label th:for="|educations[${iterStat.index}].degree|">学位</label>
                    <input type="text" th:id="|educations[${iterStat.index}].degree|"
                           th:name="|educations[${iterStat.index}].degree|"
                           th:value="${edu.degree}" required>
                </div>
                <div class="form-group">
                    <label th:for="|educations[${iterStat.index}].start_date|">开始日期</label>
                    <input type="date" th:id="|educations[${iterStat.index}].start_date|"
                           th:name="|educations[${iterStat.index}].start_date|"
                           th:value="${edu.start_date}" required>
                </div>
                <div class="form-group">
                    <label th:for="|educations[${iterStat.index}].end_date|">结束日期</label>
                    <input type="date" th:id="|educations[${iterStat.index}].end_date|"
                           th:name="|educations[${iterStat.index}].end_date|"
                           th:value="${edu.end_date}" required>
                </div>
            </div>
        </div>
        <button type="button" class="add-btn" onclick="addEducation()">添加教育经历</button>
    </div>

    <div class="section">
        <h2>工作经历</h2>
        <div id="work-container">
            <div class="item-container" th:each="work, iterStat : ${workExperiences}">
                <button type="button" class="remove-btn" onclick="removeItem(this)">×</button>
                <input type="hidden" th:name="|workExperiences[${iterStat.index}].id|" th:value="${work.id}">
                <div class="form-group">
                    <label th:for="|workExperiences[${iterStat.index}].company_name|">公司名称</label>
                    <input type="text" th:id="|workExperiences[${iterStat.index}].company_name|"
                           th:name="|workExperiences[${iterStat.index}].company_name|"
                           th:value="${work.company_name}" required>
                </div>
                <div class="form-group">
                    <label th:for="|workExperiences[${iterStat.index}].job_title|">职位</label>
                    <input type="text" th:id="|workExperiences[${iterStat.index}].job_title|"
                           th:name="|workExperiences[${iterStat.index}].job_title|"
                           th:value="${work.job_title}" required>
                </div>
                <div class="form-group">
                    <label th:for="|workExperiences[${iterStat.index}].start_date|">开始日期</label>
                    <input type="date" th:id="|workExperiences[${iterStat.index}].start_date|"
                           th:name="|workExperiences[${iterStat.index}].start_date|"
                           th:value="${work.start_date}" required>
                </div>
                <div class="form-group">
                    <label th:for="|workExperiences[${iterStat.index}].end_date|">结束日期</label>
                    <input type="date" th:id="|workExperiences[${iterStat.index}].end_date|"
                           th:name="|workExperiences[${iterStat.index}].end_date|"
                           th:value="${work.end_date}" required>
                </div>
                <div class="form-group">
                    <label th:for="|workExperiences[${iterStat.index}].description|">工作描述</label>
                    <textarea th:id="|workExperiences[${iterStat.index}].description|"
                              th:name="|workExperiences[${iterStat.index}].description|" required
                              th:text="${work.description}"></textarea>
                </div>
            </div>
        </div>
        <button type="button" class="add-btn" onclick="addWorkExperience()">添加工作经历</button>
    </div>

    <div class="section">
        <h2>校园经历</h2>
        <div id="campus-container">
            <div class="item-container" th:each="campus, iterStat : ${campusExperiences}">
                <button type="button" class="remove-btn" onclick="removeItem(this)">×</button>
                <input type="hidden" th:name="|campusExperiences[${iterStat.index}].id|" th:value="${campus.id}">
                <div class="form-group">
                    <label th:for="|campusExperiences[${iterStat.index}].organization|">组织名称</label>
                    <input type="text" th:id="|campusExperiences[${iterStat.index}].organization|"
                           th:name="|campusExperiences[${iterStat.index}].organization|"
                           th:value="${campus.organization}" required>
                </div>
                <div class="form-group">
                    <label th:for="|campusExperiences[${iterStat.index}].position|">职位</label>
                    <input type="text" th:id="|campusExperiences[${iterStat.index}].position|"
                           th:name="|campusExperiences[${iterStat.index}].position|"
                           th:value="${campus.position}" required>
                </div>
                <div class="form-group">
                    <label th:for="|campusExperiences[${iterStat.index}].start_date|">开始日期</label>
                    <input type="date" th:id="|campusExperiences[${iterStat.index}].start_date|"
                           th:name="|campusExperiences[${iterStat.index}].start_date|"
                           th:value="${campus.start_date}" required>
                </div>
                <div class="form-group">
                    <label th:for="|campusExperiences[${iterStat.index}].end_date|">结束日期</label>
                    <input type="date" th:id="|campusExperiences[${iterStat.index}].end_date|"
                           th:name="|campusExperiences[${iterStat.index}].end_date|"
                           th:value="${campus.end_date}" required>
                </div>
            </div>
        </div>
        <button type="button" class="add-btn" onclick="addCampusExperience()">添加校园经历</button>
    </div>

    <div class="section">
        <h2>技能与证书</h2>
        <div id="skill-container">
            <div class="item-container" th:each="skill, iterStat : ${skills}">
                <button type="button" class="remove-btn" onclick="removeItem(this)">×</button>
                <input type="hidden" th:name="|skills[${iterStat.index}].id|" th:value="${skill.id}">
                <div class="form-group">
                    <label th:for="|skills[${iterStat.index}].certificate_name|">证书/技能名称</label>
                    <input type="text" th:id="|skills[${iterStat.index}].certificate_name|"
                           th:name="|skills[${iterStat.index}].certificate_name|"
                           th:value="${skill.certificate_name}" required>
                </div>
            </div>
        </div>
        <button type="button" class="add-btn" onclick="addSkill()">添加技能/证书</button>
    </div>

    <div class="section">
        <h2>自我评价</h2>
        <div class="form-group">
            <textarea id="evaluation" name="evaluation.content" required th:text="${evaluation.content}"></textarea>
        </div>
    </div>

    <div class="form-actions">
        <button type="button" class="btn-danger" onclick="window.history.back()">取消</button>
        <button type="submit" class="btn-success">保存修改</button>
    </div>
</form>

<script>
    let educationCount = document.getElementById('education-container').children.length;
    let workCount = document.getElementById('work-container').children.length;
    let campusCount = document.getElementById('campus-container').children.length;
    let skillCount = document.getElementById('skill-container').children.length;

    function removeItem(button) {
        if (confirm('确定要删除此项吗？')) {
            button.parentElement.remove();
        }
    }

    function addEducation() {
        const container = document.getElementById('education-container');
        const newItem = document.createElement('div');
        newItem.className = 'item-container';
        newItem.innerHTML = `
            <button type="button" class="remove-btn" onclick="removeItem(this)">×</button>
            <input type="hidden" name="educations[${educationCount}].id" value="0">
            <div class="form-group">
                <label for="educations[${educationCount}].school_name">学校名称</label>
                <input type="text" name="educations[${educationCount}].school_name" required>
            </div>
            <div class="form-group">
                <label for="educations[${educationCount}].major">专业</label>
                <input type="text" name="educations[${educationCount}].major" required>
            </div>
            <div class="form-group">
                <label for="educations[${educationCount}].degree">学位</label>
                <input type="text" name="educations[${educationCount}].degree" required>
            </div>
            <div class="form-group">
                <label for="educations[${educationCount}].start_date">开始日期</label>
                <input type="date" name="educations[${educationCount}].start_date" required>
            </div>
            <div class="form-group">
                <label for="educations[${educationCount}].end_date">结束日期</label>
                <input type="date" name="educations[${educationCount}].end_date" required>
            </div>
        `;
        container.appendChild(newItem);
        educationCount++;
    }

    function addWorkExperience() {
        const container = document.getElementById('work-container');
        const newItem = document.createElement('div');
        newItem.className = 'item-container';
        newItem.innerHTML = `
            <button type="button" class="remove-btn" onclick="removeItem(this)">×</button>
            <input type="hidden" name="workExperiences[${workCount}].id" value="0">
            <div class="form-group">
                <label for="workExperiences[${workCount}].company_name">公司名称</label>
                <input type="text" name="workExperiences[${workCount}].company_name" required>
            </div>
            <div class="form-group">
                <label for="workExperiences[${workCount}].job_title">职位</label>
                <input type="text" name="workExperiences[${workCount}].job_title" required>
            </div>
            <div class="form-group">
                <label for="workExperiences[${workCount}].start_date">开始日期</label>
                <input type="date" name="workExperiences[${workCount}].start_date" required>
            </div>
            <div class="form-group">
                <label for="workExperiences[${workCount}].end_date">结束日期</label>
                <input type="date" name="workExperiences[${workCount}].end_date" required>
            </div>
            <div class="form-group">
                <label for="workExperiences[${workCount}].description">工作描述</label>
                <textarea name="workExperiences[${workCount}].description" required></textarea>
            </div>
        `;
        container.appendChild(newItem);
        workCount++;
    }

    function addCampusExperience() {
        const container = document.getElementById('campus-container');
        const newItem = document.createElement('div');
        newItem.className = 'item-container';
        newItem.innerHTML = `
            <button type="button" class="remove-btn" onclick="removeItem(this)">×</button>
            <input type="hidden" name="campusExperiences[${campusCount}].id" value="0">
            <div class="form-group">
                <label for="campusExperiences[${campusCount}].organization">组织名称</label>
                <input type="text" name="campusExperiences[${campusCount}].organization" required>
            </div>
            <div class="form-group">
                <label for="campusExperiences[${campusCount}].position">职位</label>
                <input type="text" name="campusExperiences[${campusCount}].position" required>
            </div>
            <div class="form-group">
                <label for="campusExperiences[${campusCount}].start_date">开始日期</label>
                <input type="date" name="campusExperiences[${campusCount}].start_date" required>
            </div>
            <div class="form-group">
                <label for="campusExperiences[${campusCount}].end_date">结束日期</label>
                <input type="date" name="campusExperiences[${campusCount}].end_date" required>
            </div>
        `;
        container.appendChild(newItem);
        campusCount++;
    }

    function addSkill() {
        const container = document.getElementById('skill-container');
        const newItem = document.createElement('div');
        newItem.className = 'item-container';
        newItem.innerHTML = `
            <button type="button" class="remove-btn" onclick="removeItem(this)">×</button>
            <input type="hidden" name="skills[${skillCount}].id" value="0">
            <div class="form-group">
                <label for="skills[${skillCount}].certificate_name">证书/技能名称</label>
                <input type="text" name="skills[${skillCount}].certificate_name" required>
            </div>
        `;
        container.appendChild(newItem);
        skillCount++;
    }
</script>
</body>
</html>